package com.inboyu.application.service;

import com.inboyu.admin.domain.ContractDomainService;
import com.inboyu.application.OrderApplicationService;
import com.inboyu.listing.domain.ListingDomainService;
import com.inboyu.operation.domain.CustomerDomainService;
import com.inboyu.order.domain.ContractAggregation;
import com.inboyu.order.domain.OrderDomainService;

public class OrderAppServiceImpl implements OrderApplicationService {

    private OrderDomainService orderDomainService;

    private CustomerDomainService customerDomainService;

    private ListingDomainService listingDomainService;

    private ContractDomainService contractDomainService;

    @Override
    public int createOrder(ContractAggregation contractAggregation) {
        // 1、租赁人信息校验
        customerDomainService.findCustomerById(contractAggregation.getCustomer().getId().id());
        // 2、房间信息校验
        orderDomainService.findRoomById(contractAggregation.getRoomEntity().getId().id());
        // 3、费项信息校验
//        listingDomainService.findFeeItemByServiceType(contractAggregation.getServiceType().code());
        // 4、创建合同
        contractDomainService.saveContract(contractAggregation.getContractEntity());
        // 5、创建订单
        return orderDomainService.createOrder(contractAggregation);
    }

    @Override
    public int updateOrder(ContractAggregation contractAggregation) {
        // 1、租赁人信息校验
        customerDomainService.findCustomerById(contractAggregation.getCustomer().getId().id());
        // 2、房间信息校验
        orderDomainService.findRoomById(contractAggregation.getRoomEntity().getId().id());
        // 3、费项信息校验
//        listingDomainService.findFeeItemByServiceType(contractAggregation.getServiceType().code());
        // 4、更新合同
        contractDomainService.saveContract(contractAggregation.getContractEntity());
        // 5、更新订单
        return orderDomainService.updateOrder(contractAggregation);
    }
}
